/*
 * @Author: wurangkun wurangkun@qq.com
 * @Date: 2023-04-06 11:56:38
 * @LastEditors: wurangkun wurangkun@qq.com
 * @LastEditTime: 2023-05-26 11:35:22
 * @FilePath: \myblog_server\src\middleware\getparams.ts
 * @Description: 获取请求参数
 */
module.exports = function () {
	return async function getParams(ctx, next) {
		console.log(`${new Date().toISOString()} ${ctx.method} ${ctx.url}`);
    if (ctx.method === 'POST') {
      ctx.mydata = ctx.request.body; // 从请求体中获取 POST 数据
      if(ctx.request.type === 'multipart/form-data'){
        ctx.mydata.files = ctx.request.files.file;
      }
    }else {
      ctx.mydata = ctx.query
    }
		await next();
	};
};